<?php namespace Common\Model;
use Hdphp\Model\Model;

class DetailInfo extends Model{
    protected $table='user';

    protected $validate=array(
        array('usernickname','required','用户昵称不为空',3,3),
        array('useremail','required','用户邮箱不为空',3,3),
        array('useremail','email','用户邮箱格式不正确',3,3),
        array('usermobile','required','用户手机号不为空',3,3),
        array('usermobile','phone','用户手机号格式不正确',3,3),
        array('usertruename','required','用户真实姓名不为空',3,3),
        array('useremail','required','用户邮箱不为空',3,3),
        array('year','required','用户生日不为空',3,3),
        array('month','required','用户生日不为空',3,3),
        array('day','required','用户生日不为空',3,3),
        array('userqq','required','用户qq号不为空',3,3),
    );

    public function store(){
        if(!$this->create()) return false;
//        p(Q('post.'));die;
        $uid=Q('post.uid');
        $data=[
            'year'=>Q('post.year'),
            'month'=>Q('post.month'),
            'day'=>Q('post.day'),
        ];
        $userimg=Q('post.userimg');
        if(!isset($userimg)){
            $userimg=Db::table('user')->where("uid={$uid}")->pluck('userimg');
            $this->data['userimg']=$userimg;
        }else{
            $olduserimg=Db::table('user')->where("uid={$uid}")->pluck('userimg');
            unlink($olduserimg);
            Db::table('user')->where("uid={$uid}")->update(['userimg'=>'']);
            $this->data['userimg']=$userimg;
        }
        $this->data['userbirthday']=implode('-',$data);
        $this->save();
        return true;
    }
}